﻿@using System.ComponentModel

<Table DataSource="@data" Bordered>
  <PropertyColumn Property="c=>c.Name" ColSpan="@GetColSpan(context.Key,"name")"></PropertyColumn>
  <PropertyColumn Property="c=>c.Age" ColSpan="@GetColSpan(context.Key)"></PropertyColumn>
  <PropertyColumn Property="c=>c.Tel" Title="Home phone" HeaderColSpan="2" RowSpan="@GetRowSpan(context.Key)" ColSpan="@GetColSpan(context.Key)"></PropertyColumn>
  <PropertyColumn Property="c=>c.Phone" HeaderColSpan="0" ColSpan="@GetColSpan(context.Key)"></PropertyColumn>
  <PropertyColumn Property="c=>c.Address" ColSpan="@GetColSpan(context.Key)"></PropertyColumn>
</Table>

@code {
  Data[] data =  {
    new Data(){ Key="1",Name="John Brown",Age=32,Tel="0571-22098909",Phone="18889898989",Address="New York No. 1 Lake Park"},
    new Data(){Key="2",Name="Jim Green",Tel="0571-22098333",Phone = "18889898888",Age = 42,Address="London No. 1 Lake Park"},
    new Data(){Key="3",Name="Joe Black",Age = 32,Tel="0575-22098909",Phone = "18900010002",Address="Sidney No. 1 Lake Park"},
    new Data(){Key="4",Name="Jim Red",Age = 18,Tel="0575-22098909",Phone = "18900010002",Address="London No. 2 Lake Park"},
    new Data(){Key="5",Name="Jake White",Age = 18,Tel="0575-22098909",Phone = "18900010002",Address="Dublin No. 2 Lake Park"}
  };

  public class Data
  {
    public string Key { get; set; }

    public string Name { get; set; }

    public int Age { get; set; }

    public string Tel { get; set; }

    public string Phone { get; set; }

    public string Address { get; set; }
  }

  private int GetRowSpan(string key)
  {
    if (key == "3")
      return 2;
    else if (key == "4")
      return 0;
    else
      return 1;
  }

  private int GetColSpan(string key, string columnTitle = "")
  {
    if (key == "5")
      if (columnTitle == "name")
        return 5;
      else
        return 0;
    else
      return 1;
  }
}